package com.yunpuvip.sachet.rest.config;

import com.yunpuvip.sachet.rest.config.properties.RestProperties;
import com.yunpuvip.sachet.rest.modular.auth.filter.AuthFilter;
import com.yunpuvip.sachet.rest.modular.auth.security.DataSecurityAction;
import com.yunpuvip.sachet.rest.modular.auth.security.impl.Base64SecurityAction;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * web配置
 *
 * @author fengshuonan
 * @date 2017-08-23 15:48
 */
@Configuration
public class WebConfig extends WebMvcConfigurationSupport {
    @Bean
    @ConditionalOnProperty(prefix = RestProperties.REST_PREFIX, name = "auth-open", havingValue = "true", matchIfMissing = true)
    public AuthFilter jwtAuthenticationTokenFilter() {
        return new AuthFilter();
    }

    @Bean
    public DataSecurityAction dataSecurityAction() {
        return new Base64SecurityAction();
    }

//    此拦截会拦截微信 特殊字符
//    @Bean(name = "corsFilter")
//    public CorsFilter corsFilter() {
//        return new CorsFilter();
//    }

//    @Bean
//   public FilterRegistrationBean frb(){
//       FilterRegistrationBean<CorsFilter> filterRegistrationBean = new FilterRegistrationBean(corsFilter());
////       System.err.println("跨域过滤器的加载22");
//       filterRegistrationBean.addUrlPatterns("/*");
//        return filterRegistrationBean;
//    }


//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//         // addPathPatterns 用于添加拦截规则
//        // excludePathPatterns 用户排除拦截
//       /* System.err.println("加载拦截器");
//        InterceptorRegistration interceptor = registry.addInterceptor(new AgentLoginInterceptor());
//        interceptor.excludePathPatterns("/store/login");
//        interceptor.addPathPatterns("/store");
//        super.addInterceptors(registry);*/
//
//    }


}
